﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.ETL.Properties;

namespace Workflows.Components.ETL
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class TablePartitionComponent:WorkflowComponentBase
    {
        #region Overrides of WorkflowComponentBase

        private TablePartitionInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction = (TablePartitionInstruction) value; }
        }

        private TablePartitionOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output = (TablePartitionOutput) value;}
        }

        #endregion

        /// <summary>
        /// 
        /// </summary>
        public TablePartitionComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.ETL.ToString();
            this.Description = "Partition table based on column name";
            this.ComponentIcon = Resources.Threading;
            this.ComponentImage = Resources.Threading48;
            this.ComponentName = "Table partition";

            this._Instruction=new TablePartitionInstruction(
                this.ComponentID,Guid.Empty,string.Empty,string.Empty,
                string.Empty, new List<string>(), false, string.Empty,1);
            this._Output=new TablePartitionOutput(this.ComponentID,Guid.Empty,0);
        }

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            TablePartitionComponent component = (TablePartitionComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
